.TH std::experimental::filesystem::path::path 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::filesystem::path::path \- std::experimental::filesystem::path::path

.SH Synopsis
   path();                                                      \fB(1)\fP (filesystem TS)
   path( const path& p );                                       \fB(2)\fP (filesystem TS)
   path( path&& p );                                            \fB(3)\fP (filesystem TS)
   template< class Source >                                     \fB(4)\fP (filesystem TS)
   path( const Source& source );
   template< class InputIt >                                    \fB(5)\fP (filesystem TS)
   path( InputIt first, InputIt last );
   template< class Source >                                     \fB(6)\fP (filesystem TS)
   path( const Source& source, const std::locale& loc );
   template< class InputIt >                                    \fB(7)\fP (filesystem TS)
   path( InputIt first, InputIt last, const std::locale& loc );

   Constructs a new path object.

   1) Constructs an empty path.
   2) Copy constructor. Constructs a copy of p.
   3) Move constructor. Constructs a copy of p, p is left in valid but unspecified
   state.
   4,5) Constructs the path from a character sequence provided by source \fB(4)\fP, which is
   a pointer or an input iterator to a null-terminated character/wide character
   sequence or an std::basic_string, or represented as a pair of input iterators
   [first, last) \fB(5)\fP. Any of the four character types char, char16_t, char32_t, wchar_t
   is allowed, and the method of conversion to the native character set depends on the
   character type used by source.

     * If the source character type is char, the encoding of the source is assumed to
       be the native narrow encoding (so no conversion takes place on POSIX systems).
     * If the source character type is char16_t, conversion from UTF-16 to native
       filesystem encoding is used.
     * If the source character type is char32_t, conversion from UTF-32 to native
       filesystem encoding is used.
     * If the source character type is wchar_t, the input is assumed to be the native
       wide encoding (so no conversion takes places on Windows).
   6,7) Constructs the path from a character sequence provided by source \fB(6)\fP, which is
   a pointer or an input iterator to a null-terminated character sequence or an
   std::string, or represented as a pair of input iterators [first, last) \fB(7)\fP. The only
   character type allowed is char. Uses loc to perform the character encoding
   conversion. If value_type is wchar_t, converts from to wide using the
   std::codecvt<wchar_t, char, std::mbstate_t> facet of loc. Otherwise, first converts
   to wide using the std::codecvt<wchar_t, char, std::mbstate_t> facet and then
   converts to filesystem native character type using std::codecvt<wchar_t, value_type>
   facet of loc.

.SH Parameters

   p           - a path to copy
                 a std::basic_string, pointer to a null-terminated character string, or
   source      - an input iterator with a character value type that points to a
                 null-terminated character sequence (the character type must be char
                 for overload \fB(6)\fP
   first, last - pair of LegacyInputIterators that specify a UTF-8 encoded character
                 sequence
   loc         - locale that defines encoding conversion to use
.SH Type requirements
   -
   InputIt must meet the requirements of LegacyInputIterator.
   -
   The value type of InputIt must be one of the four character types char, wchar_t,
   char16_t and char32_t to use the overload \fB(5)\fP.
   -
   The value type of InputIt must be char to use the overload \fB(7)\fP.

.SH Exceptions

   1,2) \fI(none)\fP
   3)
   noexcept specification:
   noexcept

   4-7) \fI(none)\fP

.SH Notes

   For portable pathname generation from Unicode strings, see u8path.

.SH Example


// Run this code

 #include <experimental/filesystem>
 #include <iostream>
 namespace fs = std::experimental::filesystem;

 int main()
 {
     fs::path p1 = "/usr/lib/sendmail.cf"; // portable format
     fs::path p2 = "C:\\\\users\\\\abcdef\\\\AppData\\\\Local\\\\Temp\\\\"; // native format
     fs::path p3 = L"D:/猫.txt"; // wide string

     std::cout << "p1 = " << p1 << '\\n'
               << "p2 = " << p2 << '\\n'
               << "p3 = " << p3 << '\\n';
 }

.SH Output:

 p1 = "/usr/lib/sendmail.cf"
 p2 = "C:\\users\\abcdef\\AppData\\Local\\Temp\\"
 p3 = "D:/猫.txt"

.SH See also

   u8path creates a path from a UTF-8 encoded source
          \fI(function)\fP

.SH Categories:
     * Noindexed pages
     * unconditionally noexcept
.SH Hidden categories:
     * Pages with unreviewed unconditional noexcept template
     * Pages with unreviewed noexcept template
